<?php

namespace Modules\Asset\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\Asset\Entities\RedpackSku;
use Modules\Asset\Entities\AssetOrder as Order;


use Validator;
use ThrowException;
use Auth;
use Setting;
use DB;


// 积分充值
class RedpackOrderController extends Controller
{
    // 提交
    public function confirm(Request $req)
    {
        $rule = [
            'sku_id' => ['required'],
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $user = Auth::requireLoginUser();

        // 奖品
        $sku = RedpackSku::getEntity([
            'id' => $req->sku_id,
            'status' => 1
        ]);

        // 运费
        $carriage = 0;

        // 虚拟资产订单发放
        $skuableMaps = [
            [
                'skuable' => $sku,
                'total' => 1
            ]
        ];

        $order = Order::initWith($skuableMaps, $user, NULL);

        $order->createAll();

        return $order->generateResponse();
    }
}
